﻿
#if DO_NOT_COMPILE_THIS

#region clientSupport



/*
 * module for communication between apps
 * 
 * please use your own namespace, better dont use my (default) one !!
 * 
 * created by: asida@centrum.cz
 * 
 * initial implementation: 6.12.2011
 * last updated:
 */

using System.IO;
using System.Text;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;



namespace SilverlightApplication1 //give it your name here
{




  /// <summary>
  /// base class that server functions for JSON serialization
  /// </summary>
  /// <typeparam name="T">target type</typeparam>
  public abstract class JsonSerializable<T>
  {


    /// <summary>
    /// serializuje instanci objektu do Json
    /// </summary>
    /// <returns>vraci <c>string</c> s Json reprezentaci objektu</returns>
    public string ToJson()
    {
      using (var memoryStream = new MemoryStream())
      {
        //var serializer = new DataContractSerializer(typeof(T));
        //serializer.WriteObject(memoryStream, this);

        var serializer = new DataContractJsonSerializer(typeof(T));
        serializer.WriteObject(memoryStream, this);

        memoryStream.Seek(0, SeekOrigin.Begin);

        var reader = new StreamReader(memoryStream);
        string content = reader.ReadToEnd();
        return content;
      }
    }





    /// <summary>
    /// Staticka funkce, nacte ze vstupniho <c>string</c> data
    /// a prevede je na konkretni objekt jako je jprl, ku, apod...
    /// </summary>
    /// <param name="data">vstupni retezec s Json daty</param>
    /// <returns>objekt dle typu</returns>
    public static T Parse(string data)
    {
      using (var stream = new MemoryStream(Encoding.Unicode.GetBytes(data)))
      {
        //var serializer = new DataContractSerializer(typeof(T));
        //T theObject = (T)serializer.ReadObject(stream);
        //return theObject;


        DataContractJsonSerializer s =
          new DataContractJsonSerializer(typeof(T));
        T theObject = (T)s.ReadObject(stream);
        return theObject;

      }
    }


  }




  /// <summary>
  /// vyjmenovane typy jprl
  /// </summary>
  public enum TypJprlEnum : int
  { 
    psk = 0,
    bzl = 1,
    jp = 2,
    op = 3
  }





  /// <summary>
  /// vyjmenovane typy parcel
  /// </summary>
  public enum TypParcelyEnum : int
  {
    kn = 0,
    pk = 1
  }






  /// <summary>
  /// jednotka prostoroveho rozdeleni lesa, dle lesniho zakona
  /// </summary>
  public class Jprl : JsonSerializable<Jprl>
  {

    public TypJprlEnum TypJprl { get; set; }
    public int LhcKod { get; set; }
    public int Odd { get; set; }
    public int OddId { get; set; }
    public string Dil { get; set; }
    public string Por { get; set; }
    public int Maj { get; set; }
    public int Katuze { get; set; }
    public string PskBzlJpOp { get; set; }
    public string BzlJpOpId { get; set; }

  }


  /// <summary>
  /// lesni hospodarsky celek
  /// </summary>
  public class Lhc : JsonSerializable<Lhc>
  {
    public int LhcKod { get; set; }
  }




  /// <summary>
  /// lesni hospodarska osnova, majetek jednoho vlasnika
  /// </summary>
  public class MajLhc : JsonSerializable<MajLhc>
  {
    public int LhcKod { get; set; }
    public int Maj { get; set; }
  }




  /// <summary>
  /// rozsah mapy
  /// </summary>
  public class MapRange : JsonSerializable<MapRange>
  {
    public double left { get; set; }
    public double right { get; set; }
    public double bottom { get; set; }
    public double top { get; set; }
  }




  public enum CommandTypeEnum : int
  {

    // XapExplorer commands reserved 0 - 255
    /// <summary>
    /// XapExplorer loads and run new app from available apps
    /// given by TargetApplicationName property in command
    /// and saves command parameter (if present)
    /// </summary>
    RunApplication = 1,

    /// <summary>
    /// stop application given by TargetApplicationName
    /// </summary>
    StopApplication = 2,

    /// <summary>
    /// after application success load, it can tell back to XapExplorer
    /// that is ready to listen to commands.
    /// If pending commmand exists for this app XapBrowser sends it to app now
    /// </summary>
    ActivateCommunication = 3,

    /// <summary>
    /// changes text on running application tab button
    /// to text given by Command parameter
    /// </summary>
    ChangeAppTabBtnLabel = 4,


    //user defined messages...

    ZmenaLhc = 256,
    ZmenaLhcMaj = 257,
    ZmenaJprl = 258,
    ZmenaKu = 259,
    ZmenaParcely = 260,

    /// <summary>
    /// command for map to move its current view position
    /// if targetAppName is specified, only this map should move
    /// </summary>
    MapMove = 261,

    ZobrazInfoOParcele = 262,
    ZobrazInfoOJprl = 263,
    ZobrazInfoOLhc = 264,

  }




  /// <summary>
  /// trida Command, predstavuje prikaz, ktery je mozne odeslat/prijmout v aplikaci
  /// </summary>
  public class Command : JsonSerializable<Command>
  {
    public CommandTypeEnum CommandType { get; set; }
    public string TargetApplicationName { get; set; }
    public string CommandParameter { get; set; }
  }




}

#endregion clientSupport

#endif